package com.bf.xpdd.persistent.sqlmapdao;

import java.sql.SQLException;
import java.util.List;

import org.springframework.stereotype.Component;

import com.bf.xpdd.domain.ActivityGlobal;
import com.bf.xpdd.domain.ActivitySettingBean;
import com.bf.xpdd.domain.SiteSeller;
import com.bf.xpdd.persistent.iface.DaoSeller;
import com.ibatis.sqlmap.client.SqlMapClient;

/**
 * dao seller
 * @author Fantastic
 * @version 1.0.0 2011-06-25
 * @since 1.0.0
 */
@Component
public class DaoSellerImpl implements DaoSeller
{

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean querySellerIsExist(SqlMapClient sqlMapClient, SiteSeller seller) throws SQLException
	{
		Object obj = sqlMapClient.queryForObject("seller.queryUserIsExit", seller);
		if(null == obj || "".equals(obj.toString()))
		{
			return false;
		}
		return true;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public long insertNewSeller(SqlMapClient sqlMapClient, SiteSeller seller) throws SQLException
	{
		return Integer.parseInt(sqlMapClient.insert("seller.insertNewSeller", seller).toString());
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void insertActivityGlobal(SqlMapClient sqlMapClient,
			ActivityGlobal global) throws SQLException 
	{
		sqlMapClient.insert("seller.insertActivityGlobal", global);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void insertActivitySetting(SqlMapClient sqlMapClient, ActivitySettingBean setting)
			throws SQLException
	{
		sqlMapClient.insert("seller.insertActivitySetting", setting);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean querySellerSessionKeyIsExist(SqlMapClient sqlMapClient, SiteSeller seller) throws SQLException 
	{
		Object obj = sqlMapClient.queryForObject("seller.querySellerSessionKeyIsExist", seller);
		if(null == obj || "".equals(obj.toString()))
		{
			return false;
		}
		return true;
	}

	/**
	 * {@inheritDoc}
	 * @throws SQLException 
	 */
	@Override
	public void updateSellerSessionKey(SqlMapClient sqlMapClient, SiteSeller seller) throws SQLException 
	{
		sqlMapClient.update("seller.updateSellerSessionKey", seller);
	}
	
	/**
	 * {@inheritDoc}
	 * @throws SQLException 
	 */
	@Override
	public void insertSellerSessionKey(SqlMapClient sqlMapClient, SiteSeller seller) throws SQLException 
	{
		sqlMapClient.insert("seller.insertSellerSessionKey", seller);
	}

	/**
	 * {@inheritDoc}
	 * @throws SQLException 
	 */
	@Override
	public List<SiteSeller> queryAllSellerSessionKeyActive(SqlMapClient sqlMapClient) throws SQLException 
	{
		return sqlMapClient.queryForList("seller.queryAllSellerSessionKeyActive");
	}

	/**
	 * {@inheritDoc}
	 * @throws SQLException 
	 */
	@Override
	public SiteSeller querySessionKeyByNick(SqlMapClient sqlMapClient, String nick)
			throws SQLException
	{
		Object obj = sqlMapClient.queryForObject("seller.querySessionKeyByNick", nick);
		if(null != obj && !"".equals(obj.toString()))
		{
			return (SiteSeller) obj;
		}
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void deleteSellerSessionKeyByNick(SqlMapClient sqlMapClient, SiteSeller seller)
			throws SQLException {
		sqlMapClient.delete("seller.deleteSellerSessionKeyByNick", seller);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void deleteAllSellerSessionKey(SqlMapClient sqlMapClient)
			throws SQLException {
		sqlMapClient.delete("seller.deleteAllSellerSessionKey");
	}
	
}
